/*
 * @Author: 王维铭 2061550880@qq.com
 * @Date: 2025-02-28 11:28:43
 * @LastEditors: 王维铭 2061550880@qq.com
 * @LastEditTime: 2025-02-28 14:11:11
 * @FilePath: \盐师22Git仓库\day05\Test05.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day05;

public class Test05 {
    public static void main(String[] args) {
        int [] array = {1,2,3,4,5};
        double avg = getAvg(array);
        System.out.println("该数组的平均值是："+avg);
            }
        public static double getAvg(int[] arr){
            double avg=0.0;
            //遍历数组，求和
            int sum = 0;
            for (int i = 0; i<arr.length;i++){
                System.out.println(arr[i]);
                sum += arr[i];
            }
            //元素和 除以 数组长度
            int num = arr.length;
            avg = sum / num; 
            return avg;
        }
    
}
